package com.homwee.factory.util.view;

import com.homwee.factory.FactoryActivity;
import com.homwee.factory.R;
import com.homwee.factory.util.ListViewItemView;
import com.homwee.factory.util.RespondedKeyEvent;
import com.homwee.listMenu.util.MenuItemData;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;

public class FactoryTextView extends ListViewItemView implements RespondedKeyEvent {
    private static int panelNum ;
    private static int productNum ;
    private static int lvdsSscLevelNum;
    private static int LvdsLevelNum;
    private static int memLevelNum;
	private TextView mNameTextView;// name
	private TextView mValueView;// value
	private Context context;
	private String mId;
	private MenuItemData mDataItem;
	private FactoryActivity fActivity;
	private int softwareLength;

	public FactoryTextView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		this.context = context;
		initView();
	}

	public FactoryTextView(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;
		initView();
	}

	public FactoryTextView(Context context) {
		super(context);
		this.context = context;
		if(context instanceof FactoryActivity){
			fActivity = (FactoryActivity)context;
		}
		initView();
	}

	private void initView() {
		this.addView(inflate(context, R.layout.factory_textview, null));
		mNameTextView = (TextView) findViewById(R.id.factory_textview_name);
		mValueView = (TextView) findViewById(R.id.factory_textview_value);
	}

	private void initValue() {
		mNameTextView.setText(mDataItem.mName==null?"":mDataItem.mName);
		mValueView.setText(mDataItem.mOptionStr ==null? "":mDataItem.mOptionStr);
	}

//	public void setAdapter(SetConfigListViewAdapter.DataItem mDataItem) {
//		this.mDataItem = mDataItem;
//		mId = mDataItem.getmItemID();
//		initValue();
//	}

	public String getmId() {
		return mId;
	}

	public void setmId(String mId) {
		this.mId = mId;
	}

	public int getValue() {
		return mDataItem.mInitValue;
	}

	public void setValue(int mValue) {

	}

	public void setViewName(String viewName) {
		
	}
	public TextView getNameView() {
		return mNameTextView;
	}
	public void onKeyEnter() {
	}

	public void onKeyLeft() {
	
/*		String stringID = MenuConfigManager.PANNEL_INDEX;
		String srtingProductId = MenuConfigManager.FACTORY_PRODUCT_INDEX;
		String srtingLvdsLevelId   = MenuConfigManager.FACTORY_PANEL_LVDS_LEVEL;
		String stringMemLevelId  =  MenuConfigManager.FACTORY_MEM_SSC_LEVEL; 
		String srtingLvdsSscLevelId   = MenuConfigManager.FACTORY_PANEL_LVDS_SSC_LEVEL;
		
		final TextView softWareVersion;
		softWareVersion = fActivity.getSoftWareVersion();
		MenuConfigManager mConfigManager = MenuConfigManager.getInstance(this.context);
		
		if(stringID.equals(getmId())){
			StringBuilder softwareVersionStr = new StringBuilder();
		    panelNum =mConfigManager.getNum(stringID);
			panelNum--;
			mConfigManager.setNum(stringID,panelNum);
			String panelString = mConfigManager.getString(MenuConfigManager.PANNEL_STRING).trim();
			mValueView.setText(panelString);
			Log.v("onKeyLeft_panelNum","panelNum"+panelNum);		
			softwareVersionStr.append(mConfigManager.getString(MenuConfigManager.FACTORY_SW_VERSION_STR).trim());
		    softwareLength = softwareVersionStr.indexOf("$");
		    if (softwareLength!=-1){
		        softwareVersionStr.setLength(softwareLength);
		    }
//			softwareVersionStr.setLength(softwareVersionStr.indexOf("$"));
			Log.v("softStr_length_left_pannel","=="+softwareVersionStr.length());
			softWareVersion.setText(fActivity.getString(R.string.factory_software_version)+softwareVersionStr);	
		}
		
		if (srtingProductId.equals(getmId())){
			StringBuilder softwareVersionStr = new StringBuilder();
			productNum=0;
			mConfigManager.setNum(srtingProductId,productNum);
			String productString = mConfigManager.getString(MenuConfigManager.FACTORY_PRODUCT_STRING).trim();
			mValueView.setText(productString);
			Log.v("productNum","productNum=="+productNum);
			softwareVersionStr.append(mConfigManager.getString(MenuConfigManager.FACTORY_SW_VERSION_STR).trim());
		    softwareLength = softwareVersionStr.indexOf("$");
		    if (softwareLength!=-1){
		        softwareVersionStr.setLength(softwareLength);
		    }
//			softwareVersionStr.setLength(softwareVersionStr.indexOf("$"));
			Log.v("softStr_length_left_pro","=="+softwareVersionStr.length());
			softWareVersion.setText(fActivity.getString(R.string.factory_software_version)+softwareVersionStr);	
		}
		if (srtingLvdsLevelId.equals(getmId())){
			LvdsLevelNum=0;
			Log.v("LvdsLevelNum","LvdsLevelNum=="+LvdsLevelNum);
			mConfigManager.setNum(srtingLvdsLevelId,LvdsLevelNum);
			LvdsLevelNum =mConfigManager.getNum(srtingLvdsLevelId);
			mValueView.setText("                               "+LvdsLevelNum);
			Log.v("LvdsLevelNum","LvdsLevelNum=="+LvdsLevelNum);
		}
		
		if ( stringMemLevelId.equals(getmId())){
			
        	
		    
        	memLevelNum=0;
			mConfigManager.setNum(stringMemLevelId,memLevelNum);
			memLevelNum =mConfigManager.getNum(stringMemLevelId);
			mValueView.setText("                               "+memLevelNum);
			Log.v("memLevelNum","memLevelNum=="+memLevelNum);
		    
		  }
	//	if (mConfigManager.getNum(MenuConfigManager.FACTORY_PANEL_LVDS_SSC_ON)==1){
	           if (srtingLvdsSscLevelId.equals(getmId())){
	        	
//	        	Log.v("test", "---:"+fActivity.getListView().getChildAt(0));
//	        	OptionView optionView = (OptionView)fActivity.getListView().getChildAt(0);
//	        	String  LvdsSscSwitch = optionView.getValueView().getText().toString();
//	            Log.v("LvdsSscSwitch","LvdsSscSwitch"+LvdsSscSwitch);
//	            if (LvdsSscSwitch.equals("")){
	     	       lvdsSscLevelNum=0;
		           mConfigManager.setNum(srtingLvdsSscLevelId,lvdsSscLevelNum);
		           lvdsSscLevelNum =mConfigManager.getNum(srtingLvdsSscLevelId);
		           mValueView.setText("                               "+lvdsSscLevelNum);	
	            }
*/	}

	public void onKeyRight() {
/*		
		final TextView softWareVersion;
		String stringPannelId = MenuConfigManager.PANNEL_INDEX;
		String srtingProductId  =MenuConfigManager.FACTORY_PRODUCT_INDEX;
		String srtingLvdsLevelId   = MenuConfigManager.FACTORY_PANEL_LVDS_LEVEL;
		String stringMemLevelId  =  MenuConfigManager.FACTORY_MEM_SSC_LEVEL; 
		String srtingLvdsSscLevelId   = MenuConfigManager.FACTORY_PANEL_LVDS_SSC_LEVEL;
		MenuConfigManager mConfigManager = MenuConfigManager.getInstance(this.context);
		softWareVersion = fActivity.getSoftWareVersion();
		
		if(stringPannelId.equals(getmId())){
			StringBuilder softwareVersionStr = new StringBuilder();   
			panelNum =mConfigManager.getNum(stringPannelId);
			panelNum++;
			mConfigManager.setNum(stringPannelId,panelNum);
			String panelString = mConfigManager.getString(MenuConfigManager.PANNEL_STRING).trim();
			mValueView.setText(panelString);
			softwareVersionStr.append(mConfigManager.getString(MenuConfigManager.FACTORY_SW_VERSION_STR).trim());
			softwareLength = softwareVersionStr.indexOf("$");
		    if (softwareLength!=-1){
		        softwareVersionStr.setLength(softwareLength);
		    }
//			softwareVersionStr.setLength(softwareVersionStr.indexOf("$"));
			Log.v("softStr_length_pannel_rigth","=="+softwareVersionStr.length());
			Log.v("softwareVersionStr111","softwareVersionStr"+softwareVersionStr);
			softWareVersion.setText(fActivity.getString(R.string.factory_software_version)+softwareVersionStr);	
			
			Log.v("onKeyRight_panelNum","panelNum=="+panelNum);
		}
		if (srtingProductId.equals(getmId())){	
			StringBuilder softwareVersionStr = new StringBuilder();
			Log.v("productNum","productNum"+productNum);
			productNum=1;
			Log.v("productNum","productNum"+productNum);
			mConfigManager.setNum(srtingProductId,productNum);
			String productString = mConfigManager.getString(MenuConfigManager.FACTORY_PRODUCT_STRING).trim();
			mValueView.setText(productString);
			softwareVersionStr.append(mConfigManager.getString(MenuConfigManager.FACTORY_SW_VERSION_STR).trim());
			softwareLength = softwareVersionStr.indexOf("$");
		    if (softwareLength!=-1){
		        softwareVersionStr.setLength(softwareLength);
		    }
//			softwareVersionStr.setLength(softwareVersionStr.indexOf("$"));
			Log.v("softStr_length_pro_right","=="+softwareVersionStr.length());
			Log.v("softwareVersionStr111","softwareVersionStr"+softwareVersionStr);
			softWareVersion.setText(fActivity.getString(R.string.factory_software_version)+softwareVersionStr);	
		}
		if (srtingLvdsLevelId.equals(getmId())){
			LvdsLevelNum=1;
			mConfigManager.setNum(srtingLvdsLevelId,LvdsLevelNum);
			LvdsLevelNum =mConfigManager.getNum(srtingLvdsLevelId);
			mValueView.setText("                               "+LvdsLevelNum);
			Log.v("LvdsLevelNum","LvdsLevelNum=="+LvdsLevelNum);
		}
		if (stringMemLevelId.equals(getmId())){
		
        	memLevelNum=1;
			mConfigManager.setNum(stringMemLevelId,memLevelNum);
			memLevelNum =mConfigManager.getNum(stringMemLevelId);
			mValueView.setText("                               "+memLevelNum);
			Log.v("memLevelNum","memLevelNum=="+memLevelNum);
		    
		}
		
	    if (srtingLvdsSscLevelId.equals(getmId())){
	    
//	    	Log.v("testright", "---:"+fActivity.getListView().getChildAt(0));
//        	OptionView optionView = (OptionView)fActivity.getListView().getChildAt(0);
//        	String  LvdsSscSwitch = optionView.getValueView().getText().toString();
//            Log.v("LvdsSscSwitch","LvdsSscSwitch"+LvdsSscSwitch);
//            if (LvdsSscSwitch.equals("")){
	           lvdsSscLevelNum=1;
		       mConfigManager.setNum(srtingLvdsSscLevelId,lvdsSscLevelNum);
		       lvdsSscLevelNum =mConfigManager.getNum(srtingLvdsSscLevelId);
		       mValueView.setText("                               "+lvdsSscLevelNum);	
	       }
	      	*/	
	}
 
	public void showValue(int value) {

	}

	public TextView getmValueView() {
		return mValueView;
	}

}
